bitkeeper revision 1.313 (3f0bf8a0YsfImKNTNOOIKMEz2NKZoA)
authorrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 11:12:32 +0000 (11:12 +0000)
committerrac61@labyrinth.cl.cam.ac.uk <rac61@labyrinth.cl.cam.ac.uk>
Wed, 9 Jul 2003 11:12:32 +0000 (11:12 +0000)
Add VBD delete and flush commands.
Yay, xenctl-cmdline should now be the union of domctl/xenctl-web/vdmanager's functionality.

.rootkeys
tools/control/src/org/xenoserver/cmdline/Main.java
tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java [new file with mode: 0644]
tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandVbdDelete.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/CommandVbdFlush.java [new file with mode: 0644]
tools/control/src/org/xenoserver/control/VirtualDiskManager.java

index 889b726a81d90824e1c5c40281af5978cc4feccc..7092789c9eb595cad8c6f1d076b61740f1c7f9db 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -31,6 +31,8 @@
 3f05631dMY7PMkwSY7zBFelGJ8goVg tools/control/src/org/xenoserver/cmdline/ParsePhysicalList.java
 3f05631dYDFXv6mwNFAgz3ta9kShJA tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
 3f0bdfabfXM4tMbvmV06di5U-5FfqA tools/control/src/org/xenoserver/cmdline/ParseVbdCreate.java
+3f0bf89f_DkClyexDd4EDwinZJG83A tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
+3f0bf89fvzPQqcHBq1xA0XlFiO8tLA tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
 3f0bec93F_VDIcn9oeXwJYwydX20kg tools/control/src/org/xenoserver/cmdline/ParseVbdShow.java
 3f098761TRsbDk9woUM846Q6_F7EmA tools/control/src/org/xenoserver/cmdline/ParseVdCreate.java
 3f099009pmH9MFkRYwP2V1DfsqEwdg tools/control/src/org/xenoserver/cmdline/ParseVdDelete.java
@@ -50,6 +52,8 @@
 3f05631eGWxq7bojQbMa-tGxsENIhw tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java
 3f0bdfab88VYiD26FXCDmmAAGJ8zWA tools/control/src/org/xenoserver/control/CommandVbdCreate.java
 3f0bdfabI14M5_odjCIwQbXCdauReA tools/control/src/org/xenoserver/control/CommandVbdCreatePhysical.java
+3f0bf89fcVy1cFU18hPVXkFMMLHLug tools/control/src/org/xenoserver/control/CommandVbdDelete.java
+3f0bf8a0aRDXkIGy3liS1oKXIQpeyA tools/control/src/org/xenoserver/control/CommandVbdFlush.java
 3f098761c5-idlmf9vWEMOlDw0VCHg tools/control/src/org/xenoserver/control/CommandVdCreate.java
 3f0990096KcyQw77qJmjTu941smS8A tools/control/src/org/xenoserver/control/CommandVdDelete.java
 3f0990093VJUL7QjxGigR5GPXf_Fkw tools/control/src/org/xenoserver/control/CommandVdRefresh.java
index 3b8cc554b7873b6e3b229e8bfaec10ca3354887e..caf3451437d9a7d09276dbfd26e815dbd0d97ced 100644 (file)
@@ -36,6 +36,8 @@ public class Main {
     };
   private static final CommandParser vbdcommands[] =
     { new ParseVbdCreate(),
+      new ParseVbdDelete(),
+      new ParseVbdFlush(),
       new ParseVbdShow()
     };
   private static final CommandParser commands[] =
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdDelete.java
new file mode 100644 (file)
index 0000000..f0a9786
--- /dev/null
@@ -0,0 +1,41 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdDelete;
+import org.xenoserver.control.Defaults;
+
+public class ParseVbdDelete extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        int domain_id = getIntParameter(args, 'n', 0);
+        int vbd_num = getIntParameter(args, 'v', -1);
+
+        if (domain_id == 0) {
+            throw new ParseFailedException("Expected -n<domain_id>");
+        }
+        if (vbd_num == -1) {
+            throw new ParseFailedException("Expected -v<vbd_num>");
+        }
+        loadState();
+        String output = new CommandVbdDelete(domain_id, vbd_num).execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+        saveState();
+    }
+
+    public String getName() {
+        return "delete";
+    }
+
+    public String getUsage() {
+        return "-n<domain> -v<vbd>";
+    }
+
+    public String getHelpText() {
+        return "Deletes the specified virtual block device from the specified domain.";
+    }
+
+}
diff --git a/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java b/tools/control/src/org/xenoserver/cmdline/ParseVbdFlush.java
new file mode 100644 (file)
index 0000000..3043900
--- /dev/null
@@ -0,0 +1,31 @@
+package org.xenoserver.cmdline;
+
+import java.util.LinkedList;
+
+import org.xenoserver.control.CommandFailedException;
+import org.xenoserver.control.CommandVbdFlush;
+import org.xenoserver.control.Defaults;
+
+public class ParseVbdFlush extends CommandParser {
+    public void parse(Defaults d, LinkedList args)
+        throws ParseFailedException, CommandFailedException {
+        loadState();
+        String output = new CommandVbdFlush().execute();
+        if (output != null) {
+            System.out.println(output);
+        }
+        saveState();
+    }
+
+    public String getName() {
+        return "flush";
+    }
+
+    public String getUsage() {
+        return "";
+    }
+
+    public String getHelpText() {
+        return "Delete all virtual block devices";
+    }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdDelete.java b/tools/control/src/org/xenoserver/control/CommandVbdDelete.java
new file mode 100644 (file)
index 0000000..ca1cd1e
--- /dev/null
@@ -0,0 +1,43 @@
+package org.xenoserver.control;
+
+/**
+ * Delete a virtual block device. Note that this does not update anything inside
+ * Xen, and therefore should only be done if you are certain that the domain has
+ * either not been started, or has been destroyed, or you are sure it will not
+ * try to access the VBD again. Since the mapping is not removed in Xen, any
+ * subsequent changes to the underlying virtual disk will affect the domain,
+ * probably adversely.
+ */
+public class CommandVbdDelete extends Command {
+    /** Domain id to delete from */
+    private int domain_id;
+    /** VBD number to delete */
+    private int vbd_num;
+
+    /**
+     * Constructor for CommandVbdDelete.
+     * @param domain_id Domain ID to delete from
+     * @param vbd_num VBD number to delete
+     */
+    public CommandVbdDelete(int domain_id, int vbd_num) {
+        this.domain_id = domain_id;
+        this.vbd_num = vbd_num;
+    }
+
+    /**
+     * @see org.xenoserver.control.Command#execute()
+     */
+    public String execute() throws CommandFailedException {
+        if (VirtualDiskManager
+            .IT
+            .deleteVirtualBlockDevice(domain_id, vbd_num)) {
+            return "Deleted VBD " + vbd_num + " from domain " + domain_id;
+        } else {
+            throw new CommandFailedException(
+                "No such virtual block device "
+                    + vbd_num
+                    + " in domain "
+                    + domain_id);
+        }
+    }
+}
diff --git a/tools/control/src/org/xenoserver/control/CommandVbdFlush.java b/tools/control/src/org/xenoserver/control/CommandVbdFlush.java
new file mode 100644 (file)
index 0000000..fdb5b12
--- /dev/null
@@ -0,0 +1,14 @@
+package org.xenoserver.control;
+
+/**
+ * Flush (delete) all virtual block devices.
+ */
+public class CommandVbdFlush extends Command {
+    /**
+     * @see org.xenoserver.control.Command#execute()
+     */
+    public String execute() throws CommandFailedException {
+        VirtualDiskManager.IT.flushVirtualBlockDevices();
+        return "Flushed virtual block devices";
+    }
+}
index e872790dba71d3b967beaffa74212be002e3aceb..179ee079a4cbea7b0e5847b6bc6044f482535ba8 100644 (file)
@@ -125,10 +125,11 @@ public class VirtualDiskManager {
      * Delete a virtual block device.
      * @param domain Domain owning the device.
      * @param vbdNum The vbd number within the domain.
+     * @return true if the VBD was deleted, false if it does not exist.
      */
-    void deleteVirtualBlockDevice(int domain, int vbdNum) {
+    boolean deleteVirtualBlockDevice(int domain, int vbdNum) {
         Object hash = hashVBD(domain, vbdNum);
-        virtualBlockDevices.remove(hash);
+        return virtualBlockDevices.remove(hash) != null;
     }
 
     /**